<?php
header('P3P: CP="CAO PSA OUR"');
	require_once("utils/session.php");
	require_once("utils/redirect.php");
	require_once("utils/query.php");
	require_once("utils/facebookauth.php");
	
	$result = execute_query("SELECT drupaluid FROM facebookUser WHERE facebookID = '%s'", $facebookID);
	if ($result)
	{
		$row = mysql_fetch_assoc($result);
		if ($row)
		{
			$uid = $row['drupaluid'];
			$_SESSION['uid'] = $uid;
			$_SESSION['facebookid'] = $facebookID;
			redirect("http://testcb.untoldthegame.com/facebooktesting/www/home.php/");
		}
	}
?>
<html>
	<head>
		<script type="text/javascript" src="../js/jquery-1.5.2.min.js"></script>
		<script type="text/javascript"><!--
		
			function onSubmit()
			{
				$.post
				(
					"../ajax/insertNewDruFromFacebook.php",
					{
						drupalid: $("#drupalid").val(),
						drupalpw: $("#drupalpw").val()
					},
					function(data, textStatus)
					{
						if (data.success)
						{
							$("#message").html("Logged in successfully, redirecting...");
							location.href = "http://testcb.untoldthegame.com/facebooktesting/www/home.php/";
						}
						else
						{
							$("#message").html(data.message);
						}
					},
					'json'
				);
			}
		
		--></script>
	</head>
	<body>
		<center>
			<div id="message"></div>
			If you already have an Untold account, please enter your username and password below.  If you do not have an Untold account, click the register button to be taken to the Untold registration page where you will be further instructed on creating an account. Once one gives permission for the application to access your basic Facebook information, then you should not need to log in again. Assuming the user is signed in to Facebook, that person should also be able to access the Untold application.
			<table>
					
				<tr>
					<td>Untold Username: </td>
					<td><input id="drupalid" type="text" name="drupalid"></input></td>
				</tr>
				<tr>
					<td>Password: </td>
					<td><input id="drupalpw" type="password" name="drupalpw"></input></td>
				</tr>
				<tr>
					<td><a href="http://testsite.untoldthegame.com/user/register" target="_blank">register</a></td>
					<td><input id="login" type="submit" value="Log In" onclick="onSubmit()" /></td>
				</tr>
			</table>
		</center>
	</body>
</html>
